package xyf.p11.other.slidewindow;

import java.util.HashMap;
import java.util.Map;

/**
 * ClassName: J48_LongestSubString
 * Description:
 * Author: xyf
 * Date: 9/9/22 10:18 AM
 * Version: 1.0
 **/
public class J48_LongestSubString
{
    public int lengthOfLongestSubstring(String s)
    {
        int slow = -1;
        int fast = 0;
        int max = 0;
        Map<Character, Integer> help = new HashMap<>();
        while (fast < s.length())
        {
            Integer index = help.get(s.charAt(fast));
            if (index != null && index > slow)
            {
                slow = index;
            }

            max = Math.max(max, fast - slow);
            help.put(s.charAt(fast), fast);
            fast++;
        }
        return max;
    }
}
